package com.gxa.controller;

import com.gxa.pojo.Room;
import com.gxa.service.RoomService;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Room)表控制层
 *
 * @author makejava
 * @since 2022-09-01 12:38:49
 */
@Api(tags = "房间管理控制器")
@RestController
@RequestMapping("/room")
public class RoomController {
    /**
     * 服务对象
     */
    @Resource
    private RoomService roomService;

    /**
     * 分页查询
     *
     * @param room 筛选条件
     * @return 查询结果
     */
    @ApiOperation(value = "条件查找数据并分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roomId", value = "房间id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomName", value = "房间名称", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomArea", value = "面积", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "roomBuild", value = "所属楼宇", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomFloor", value = "楼层", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "roomFurnish", value = "装修情况", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomPrice", value = "出租单价", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomTypePhoto", value = "户型图", dataType = "java.lang.String", paramType = "body"),
    })
    @PostMapping("/queryByPage")
    public ResponseData queryByPage(Room room, @ApiParam(value = "页码") int page, @ApiParam(value = "每页多少条") int size) {
        ResponseData responseData = new ResponseData();
        responseData.setData(this.roomService.queryByPage(room, page, size));
        return responseData;
    }
//
//    /**
//     * 条件查询数据
//     *
//     * @param room 条件
//     * @return 单条数据
//     */
//    @PostMapping("/query")
//    public ResponseData query(Room room) {
//        ResponseData responseData = new ResponseData();
//        responseData.setData(this.roomService.query(room));
//        return responseData;
//    }

    /**
     * 新增数据
     *
     * @param room 实体
     * @return 新增结果
     */
    @ApiOperation(value = "新增数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roomId", value = "房间id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomName", value = "房间名称", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomArea", value = "面积", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "roomBuild", value = "所属楼宇", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomFloor", value = "楼层", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "roomFurnish", value = "装修情况", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomPrice", value = "出租单价", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomTypePhoto", value = "户型图", dataType = "java.lang.String", paramType = "body"),
    })
    @PostMapping("/add")
    public ResponseData add(@RequestBody Room room) {
        ResponseData responseData = new ResponseData();
        if (this.roomService.insert(room) > 0) {
            responseData.setCode(200);
            responseData.setMsg("success");
        } else {
            responseData.setCode(404);
            responseData.setMsg("fail");
        }
        return responseData;
    }

    /**
     * 编辑数据
     *
     * @param room 实体
     * @return 编辑结果
     */
    @ApiOperation(value = "修改数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roomId", value = "房间id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomName", value = "房间名称", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomArea", value = "面积", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "roomBuild", value = "所属楼宇", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomFloor", value = "楼层", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "roomFurnish", value = "装修情况", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomPrice", value = "出租单价", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomTypePhoto", value = "户型图", dataType = "java.lang.String", paramType = "body"),
    })
    @PutMapping("/change")
    public ResponseData edit(Room room) {
        ResponseData responseData = new ResponseData();
        Room update = this.roomService.update(room);
        if (update.equals(null)) {
            responseData.setCode(404);
            responseData.setMsg("fail");
        } else {
            responseData.setCode(200);
            responseData.setData(update);
        }
        return responseData;
    }

    /**
     * 删除数据
     *
     * @param room 主键
     * @return 删除是否成功
     */
    @ApiOperation(value = "根据条件删除数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roomId", value = "房间id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomName", value = "房间名称", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomArea", value = "面积", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "roomBuild", value = "所属楼宇", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomFloor", value = "楼层", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "roomFurnish", value = "装修情况", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomPrice", value = "出租单价", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "roomTypePhoto", value = "户型图", dataType = "java.lang.String", paramType = "body"),
    })
    @DeleteMapping("/delete")
    public ResponseData deleteById(Room room) {
        ResponseData responseData = new ResponseData();
        if (this.roomService.deleteById(room)){
            responseData.setMsg("success");
        }else {
            responseData.setCode(404);
            responseData.setMsg("fail");
        }
        return responseData;
    }

}

